<template>
    <div>
<h1>病房显示</h1>
<a href="/AddRoom">去病房添加</a>
<a href="/Adddoctor">去医生新增</a>
所属科室   <select v-model="dataps.ksid">
                    <option value="0">请选择科室</option>
                    <option v-for="d in datapss" :value="d.kid">{{d.kName}}</option>
                </select>
<input type="text" placeholder="请输入病房名称模糊查" v-model="dataps.names">
<input type="button" value="查询" class="btn btn-success" @click="GetShows">
<table class="table">
    <thead>
        <tr>
            <td>病房号</td>
            <td>病房名称</td>
            <td>所属科室</td>
            <td>床位总数量</td>
            <td>状态</td>
            <td>空闲床数量</td>
            <td>创建日期</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
  <tr v-for="d in data">
            <td>{{d.roomIds}}</td>
             <td>{{d.roomName}}</td>
            <td>{{d.kName}}</td>
            <td>{{d.sumNUm}}</td>
            <td>{{d.states}}</td>
            <td>{{d.badnum}}</td>
            <td>{{moment(d.createTime).format("YYYY-MM-DD")}}</td>
            <td>
                <input type="button" :value="d.states=='启用'?'维修':'启用'" class="btn btn-success" @click="Xkzt(d.roomId)">
            </td>
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import moment from 'moment';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router=useRouter();
onMounted(()=>{
    GetShows();
    Bind();
})
const dataps=ref({
    ksid:0,
    names:""
})
const data=ref([{
      "kid": 1,
    "kName": "内科",
    "roomIds": 0,
    "roomId": 1,
    "ksId": 1,
    "roomName": "string",
    "sumNUm": 0,
    "badnum": 0,
    "states": "启用",
    "createTime": "2025-05-19T09:54:31.4875914"
}])
const GetShows=()=>{
    axios.get("/api/Room/GetRoom",{params:dataps.value}).then(res=>{
        data.value=res.data;
    })
}

//绑定下拉框
const datapss=ref([{
     "kid": 0,
    "kName": "",
}])

const Bind=()=>{
    axios.get("/api/Ks/GetDc",{params:dataps.value}).then(res=>{
        datapss.value=res.data;
    })
}
//修改状态
const Xkzt=(e:any)=>{
    if(!confirm("确定要修改状态吗"))
{
    return;
}
axios.get("/api/Room/UpState",{params:{id:e}}).then(res=>{
    if(res.data>0)
{
    alert("修改成功");
    GetShows();
}
else
{
    alert("修改失败");
}
})
}
</script>

<style scoped>

</style>